package com.hhkj.api.common.session.holder;

import com.hhkj.api.common.session.holder.model.LoginStudent;
import com.ruoyi.framework.login.api.ApiSessionHolder;
import lombok.experimental.UtilityClass;

/**
 * ApiStudentSessionHolder
 *
 * @author zheng
 * @since 2023/10/25 21:06
 */
@UtilityClass
public class ApiStudentSessionHolder {

    /**
     * TTL 设置 当前登录学员信息
     *
     * @param loginStudent 登录用户信息
     */
    public void setLoginStudent(LoginStudent loginStudent) {
        ApiSessionHolder.setSessionObj(loginStudent);
    }

    /**
     * 获取TTL中的LoginStudent
     *
     * @return 登录学员信息
     */
    public LoginStudent getLoginStudent() {

        Object sessionObj = ApiSessionHolder.getSessionObj();
        if (sessionObj instanceof LoginStudent) {
            return (LoginStudent) sessionObj;
        }
        return null;
    }


    /**
     * 获取学员id
     *
     * @return 学员id
     */
    public Long getStudentId() {
        LoginStudent loginStudent = getLoginStudent();
        if (loginStudent != null) {
            return loginStudent.getId();
        }
        return null;
    }


    /**
     * 清除
     */
    public void clear() {
        ApiSessionHolder.clear();
    }
}
